package org.devocean.groupbuying.utils;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class UriTag extends BodyTagSupport {

	/**
	 * Determine action to perform on tag body
	 * <p>
	 * Actions :
	 * <p>
	 * - Apply slugify() utility methods on tag body
	 */
	public int doAfterBody() throws JspException {

		try {
			BodyContent bc = getBodyContent();
			String body = bc.getString();
			JspWriter out = bc.getEnclosingWriter();
			if (body != null) {
				out.print(UriUtils.slugify(body));
			}
		} catch (IOException ioe) {
			throw new JspException("Error: " + ioe.getMessage());
		}
		return SKIP_BODY;
	}

}
